package com.dd.stack.mybatisplus.controller.mvcc;

import com.dd.stack.common.util.response.ApiResponse;
import com.dd.stack.mybatisplus.service.inner.impl.mvcc.ThumbUserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/9/12 14:45
 * @Description 类功能作用说明
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/thumb-user")
@Api(tags = "验证MVCC不保证数据安全性接口")
public class ThumbUserController {

    private final ThumbUserServiceImpl thumbUserService;

    //@PostMapping("/desc")
    //@ApiOperation("递减User表的java（Integer）测试字段")
    //public ApiResponse<Void> desc(){
    //    log.info("C ThumbUserController M desc()..");
    //    thumbUserService.descUserJavaFieldNoLock();
    //    return ApiResponse.success();
    //}

    @PostMapping("/desc/for-update")
    @ApiOperation("递减User表的java（Integer）测试字段（使用排他锁）")
    public ApiResponse<Void> descWithRowLock(){
        log.info("C ThumbUserController M descWithRowLock()..");
        thumbUserService.descUserJavaFieldForUpdate(94L);
        return ApiResponse.success();
    }
}
